package com.buaa.airticketbookingsystem.Controller;

import com.buaa.airticketbookingsystem.Entity.Administrator;
import com.buaa.airticketbookingsystem.Service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
public class AdminLoginController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/adminLogin")
    public Map<String, Object> adminLogin(@RequestBody Map<String, String> remap){
        String email = remap.get("email");
        String password = remap.get("password");
        Administrator ad = adminService.selectAdminByEmail(email);
        Map<String, Object> resMap = new HashMap<>();
        if(ad == null){
            resMap.put("res", false);
            resMap.put("message", "该邮箱未注册为管理员，请返回用户登录，或与管理员联系注册");
        } else{
            if(ad.getAdmin_password().equals(password)){
                resMap.put("res", true);
                resMap.put("message", "管理员登陆成功");
            } else{
                resMap.put("res", false);
                resMap.put("message", "密码错误，请重试");
            }
        }
        return resMap;
    }
}
